package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.web.entity.table.StoresTableDef;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.web.entity.Stores;
import com.dingreading.cloud.web.mapper.StoresMapper;
import com.dingreading.cloud.web.service.StoresService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

import static com.dingreading.cloud.web.entity.table.ReadstarStoreTableDef.readstarStore;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-09-11
 */
@Service
public class StoresServiceImpl extends BaseServiceImpl<StoresMapper, Stores, StoresTableDef> implements StoresService {

    @Override
    protected StoresTableDef getTable() {
        return StoresTableDef.stores;
    }

    @Override
    public Stores getByUid(String storeUid) {
        return getMapper().selectOneByCondition(table.uid.eq(storeUid));
    }

    @Override
    public List<Stores> listByEnabledAndActivited() {
        QueryCondition condition = table.enabled.eq(1)
                .and(table.activated.eq(1))
                .and(readstarStore.id.isNull());
        QueryWrapper wrapper = QueryWrapper.create()
                .select(table.allColumns)
                .from(table)
                .leftJoin(readstarStore).on(table.uid.eq(readstarStore.storeUid))
                .where(condition);
        return getMapper().selectListByQuery(wrapper);
    }
}
